<?xml version="1.0" encoding="UTF-8"?>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="OnlineExam.*, java.util.*, java.text.*, registration.*" %>

<% 
	User user = (User)session.getAttribute ("USER");
	Category cat = (Category)session.getAttribute("CATEGORY");
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<TITLE>Question Paper for <%= cat.getCategoryId() %></TITLE>
<link rel="stylesheet" type="text/css" href="http://<%= request.getServerName()%>/OnlineExam/jsp/style.css" media="screen" />
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var up,down;
var min1,sec1;
var cmin1,csec1,cmin2,csec2;

function Minutes(data) 
{
	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
	return(data.substring(0,i)); 
}

function Seconds(data) 
{
	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
	return(data.substring(i+1,data.length)); 
}

function Display(min,sec) 
{
	var disp;
	if(min<=9) 
		disp=" 0";
	else 
		disp=" ";

	disp+=min+":";

	if(sec<=9) 
		disp+="0"+sec;

	else 
		disp+=sec; return(disp); 
}

function Up() 
{
	cmin1=0;
	csec1=0;
	min1=0+Minutes(document.sw.beg1.value);
	sec1=0+Seconds(document.sw.beg1.value);
	UpRepeat(); 
}

function UpRepeat() 
{
	csec1++;
	if(csec1==60) 
	{ 
		csec1=0; cmin1++; 
	}
	document.sw.disp1.value=Display(cmin1,csec1);

	if((cmin1==min1)&&(csec1==sec1)) 
	{ 
		alert("Time Up!!!!!! -- Please Submit Your Paper");
	}
	else 
		up=setTimeout("UpRepeat()",1000); 
}

function Down() 
{
	cmin2=1*Minutes(document.sw.beg2.value);
	csec2=0+Seconds(document.sw.beg2.value);
	DownRepeat(); 
}

function DownRepeat() 
{
	csec2--;
	if(csec2==-1) 
	{ 
		csec2=59; cmin2--; 
	}
	document.sw.disp2.value=Display(cmin2,csec2);

	if ((cmin2==2) && (csec2==0)) 
		alert("U have only 2 mins left");

	if((cmin2==0)&&(csec2==0))
	{ 
		alert("Time Up!!!!! --- Click On OK To Submit Your Paper");
		document.sw.submit();
	} 
	else 
		down=setTimeout("DownRepeat()",1000); 
}
// End -->
</SCRIPT>

</HEAD>
<body onLoad="Down()">
<jsp:include page="common/header.jsp"/>
<%@page language="java" import="OnlineExam.*, OnlineExam.validator.*, registration.*"%>
<center><h2><b><Category : <%= cat.getCategoryId() %></b></h2></center><br>
<center><td><b>Candidate : <%=user.getEmailId()%></b></td><br><br>
<td><b>TestId : <%=session.getAttribute("TESTID")%></b></td></center><br /><br />
<CENTER>
<FORM NAME="sw" ACTION="DisplayQuestionPaper.do" method="POST">
<TABLE border="3" width="100%">
<TR align="center"><TD>Start at : <%= DateFormat.getInstance().format(new java.util.Date((Long)session.getAttribute("STARTTIMEMILLIS")))%></td>
<TR align="center"><TD>Ends at : <%= DateFormat.getInstance().format (new java.util.Date ((Long)session.getAttribute("ENDTIMEMILLIS")))%><br></td>
<input type="text" name="beg2" size="7" value="<%=cat.getTimeLimit()%>:00"></TD> 
<td colspan="2"><input type="text" name="disp2" size="9"></TD></TR>
</TABLE>
</CENTER> 
<%@page language="java" import="OnlineExam.question.*, java.lang.*, java.io.*"%>
<%
		int[] qnumbers = (int[])session.getAttribute("QNUMBERS");
		for (int i = 0; i < qnumbers.length; i++)
	   	{
		    Question question = Question.retrieveQuestion (qnumbers[i]);
%>
			<b>Question: <%=(i+1)%> <br /><br /><%=question.getQuestion()%> </b><br/><br/>

<%          String[] answers = question.splitOptions();
     		for (int j = 0; j < answers.length; j++)
     		{
%>
     		    <tr><td><input type="Radio" name="A<%= i %>" value = "A<%= (j + 1) %>"><%=answers[j]%></td></tr><br/><br/>
<% 			}
     		if (question.needsExplanation())
     		{
%>
          		Give an explanation for your answer:
          		<br/><br/><textarea name="Exp<%=i%>"></textarea><br/><br/>
<%
     		}
		}
%>
<br/><br />
<input type="Submit" value="Submit" onClick="document.sw.submit()">
</FORM>

<jsp:include page="common/footer.jsp"/>
</body>
</html>
